﻿using PosClient.Delegates;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PosClient.Controls
{
    public partial class Total : UserControl, INotifyPropertyChanged
    {
        public Total()
        {
            InitializeComponent();
            InitEvent();
        }

        private void InitEvent()
        {
            this.button_pay.Click += (s, e) =>
            {
                RowClick?.Invoke(s,e);
            };
        }

        public event RowClickEventHandler RowClick;

        private decimal _TotalCount;
        private decimal _TotalAmount;
        private decimal _TotalDiscount;
        private string _Svg;


        [Description("总数"), Category("外观"), DefaultValue("")]
        public decimal TotalCount
        {
            get => _TotalCount;
            set
            {
                if (_TotalCount == value) return;
                _TotalCount = value;
                avatar.Badge = _TotalCount.ToString();
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        [Description("总额"), Category("外观"), DefaultValue("")]
        public decimal TotalAmount
        {
            get => _TotalAmount;
            set
            {
                if (_TotalAmount == value) return;
                _TotalAmount = value;
                label_amount.Text = _TotalAmount.ToString();
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        [Description("总优惠"), Category("外观"), DefaultValue("")]
        public decimal TotalDiscount
        {
            get => _TotalDiscount;
            set
            {
                if (_TotalDiscount == value) return;
                _TotalDiscount = value;
                if (_TotalDiscount == 0)
                {
                    label_yhamount.Visible = false;
                }
                else
                {
                    label_yhamount.Visible = true;
                }
                label_yhamount.Text = _TotalDiscount.ToString();
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        [Description("图标Svg"), Category("外观"), DefaultValue("")]
        public string Svg
        {
            get => _Svg;
            set
            {
                if (_Svg == value) return;
                _Svg = value;
                avatar.ImageSvg = !string.IsNullOrEmpty(_Svg) ? DefaultSvg : _Svg;
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        private string DefaultSvg { get => "<svg t=\"1741749625598\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"9690\" width=\"128\" height=\"128\"><path d=\"M58 348.648a107.96 107.96 0 0 1 54.392-93.732c83.148-47.508 240.428-137.384 318.788-182.164a92.852 92.852 0 0 1 93.26 0.656l408.356 240.996a67.528 67.528 0 0 1 33.204 58.152v305.16a97.784 97.784 0 0 1-48.668 84.556l-315.216 183.128a110.832 110.832 0 0 1-112.008-0.384l-377.776-222.952A110.484 110.484 0 0 1 58 626.912V348.648z\" fill=\"#FF8142\" p-id=\"9691\"></path><path d=\"M72.736 294.2a107.928 107.928 0 0 1 39.656-39.284l318.788-182.164a92.852 92.852 0 0 1 93.26 0.656l408.356 240.996a67.44 67.44 0 0 1 24.248 24.552l-353.236 195.48a102.588 102.588 0 0 1-99.552-0.116L72.736 294.2z\" fill=\"#FFB16F\" p-id=\"9692\"></path><path d=\"M957.024 338.92a67.448 67.448 0 0 1 8.976 33.636v305.16a97.784 97.784 0 0 1-48.668 84.556l-315.216 183.128a110.744 110.744 0 0 1-55.876 14.996l2.98-315.552a141.4 141.4 0 0 1 73.432-122.664l334.372-183.26z\" fill=\"#F46B48\" p-id=\"9693\"></path><path d=\"M217.48 194.868l490.76 280.404 1.36 107.288a18.616 18.616 0 0 0 27.772 15.968l55.04-31.108a18.616 18.616 0 0 0 9.452-16.436l-1.548-125.296L312.604 140.512 217.48 194.868z\" fill=\"#BF552A\" p-id=\"9694\"></path><path d=\"M513.384 712.264c0.136-8.74-2.996-21.404-11.524-26.224l-168.688-95.412c-8.624-4.876-12.04 6.704-12.136 12.704l-2.608 163.612c-0.14 8.752 3.04 21.316 11.52 26.176l168.76 96.732c8.652 4.956 12.04-6.768 12.136-12.76l2.54-164.828z\" fill=\"#DFC7C7\" p-id=\"9695\"></path><path d=\"M489.884 717.508c0.024-1.496 0.364-3.504-2.172-4.944l-141.46-80.188c-1.444-0.82-2.288 2.328-2.288 2.396l-0.492 30.872c-0.024 1.492-0.352 3.492 2.172 4.924l141.472 80.4c1.432 0.816 2.284-2.348 2.284-2.412l0.484-31.048z\" fill=\"#CAB1B1\" p-id=\"9696\"></path><path d=\"M370.604 718.508c0.048-3.236-1.568-5.296-2.588-5.876l-22.408-12.76c-0.884-0.504-2.672-0.388-2.724 2.848l-1.1 69.324c-0.052 3.232 1.568 5.296 2.584 5.88l22.412 12.824c0.884 0.508 2.672 0.4 2.724-2.84l1.1-69.4zM415.856 744.28c0.048-3.236-1.568-5.304-2.588-5.884l-22.408-12.756c-0.884-0.504-2.672-0.388-2.724 2.852l-1.096 69.448c-0.052 3.236 1.568 5.304 2.588 5.888l22.412 12.824c0.884 0.508 2.672 0.392 2.724-2.852l1.092-69.52zM448.472 760.84c0.032-2.276-1.112-3.032-1.408-3.2l-12.164-6.928c-0.272-0.152-1.444-0.7-1.48 1.556l-1.152 73.564c-0.036 2.272 1.108 3.032 1.404 3.2l12.172 6.968c0.268 0.152 1.444 0.704 1.476-1.552l1.152-73.608zM488.816 786.336c0.052-3.408-1.636-5.852-2.88-6.564l-24.952-14.204c-1.1-0.628-2.98-0.2-3.032 3.192l-1.068 68.64c-0.052 3.408 1.636 5.852 2.88 6.568l24.956 14.28c1.1 0.628 2.98 0.204 3.032-3.188l1.064-68.724z\" fill=\"#AD95A2\" p-id=\"9697\"></path></svg>"; }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); //实现通知刷新
        }
    }
}
